//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package api_common

import (
	"context"

	"gitcode.com/eteam/api-server/dao/board_dao"
)

/*
 * 删除画板
 *
 * 1. 清除所有成员
 * 2. 删除画板信息
 */

func RemoveBoard(ctx context.Context, boardId string) error {
	//清除所有成员
	err := board_dao.MemberInfoDao.RemoveByBoard(ctx, boardId)
	if err != nil {
		return err
	}
	//删除画板信息
	boardItem, err := board_dao.BoardInfoDao.Get(ctx, boardId)
	if err != nil {
		return err
	}
	err = board_dao.BoardInfoDao.Remove(ctx, boardId)
	if err != nil {
		return err
	}
	err = board_dao.RemoveBoardInfoDao.Insert(ctx, boardItem)
	if err != nil {
		return err
	}
	return nil
}
